package com.erp.util
{

	import mx.resources.ResourceManager;
	import mx.resources.IResourceManager;

	import flash.events.Event;
	import flash.events.EventDispatcher;

	import mx.controls.Alert;

	public class LocalResourceManager extends EventDispatcher
	{

		private static const BUNDLE_NAME:String="message";

		[Bindable]
		public static var resourceManager:IResourceManager=null;

		private static var instance:LocalResourceManager=null;

		private static var currentLanguage:String="zh_CN";

		public static function getInstance():LocalResourceManager
		{
			if (instance == null)
			{
				instance=new LocalResourceManager();
				resourceManager=ResourceManager.getInstance();
				resourceManager.initializeLocaleChain([currentLanguage]);
			}
			return instance;
		}

		public function changeLanguage(languageName:String):void
		{
			resourceManager.localeChain=[languageName];
			currentLanguage=languageName;
			dispatchChange();
		}

		[Bindable("change")]
		public function getImage(resName:String):Class
		{
			var result:Class=resourceManager.getClass(BUNDLE_NAME, resName, currentLanguage);
			return result;
		}

		[Bindable("change")]
		public function getString(resName:String):String
		{
			var result:String=resourceManager.getString(BUNDLE_NAME, resName);
			return result;
		}

		private function dispatchChange():void
		{
			dispatchEvent(new Event("change"));
		}
	}
}